<template>
  <div id="app" v-if="show">
    <div v-if="type === 'cover'">
      <goal v-if="formType === 'coverGoal'" :buCode="buCode" :dcPeriod="dcPeriod" :approve="true" :height="210"></goal>
      <status v-else :buCode="buCode" :dcPeriod="dcPeriod" :approve="true" :height="210"></status>
    </div>
    <div v-else-if="type === 'dataElements'">
      <dataFIll :id="id" disabled :showProcessButton="false"></dataFIll>
    </div>
    <div v-else-if="(type === 'template'|| type === 'formData') && formType == 2">
      <apply-form-center :id="id" :recordId="recordId" :isPCurl="true" :PCurlGetData="type === 'template' ? false : true" />
    </div>
    <div v-else-if="type === 'template' && formType == 3">
      <rate-form-center :isPCurl="true" :row="{id}" />
    </div>
    <div v-else></div>
  </div>
</template>

<script>
import goal from '../views/specialManagement/coverageStatistics2.0/coverPage/goal.vue'
import status from '../views/specialManagement/coverageStatistics2.0/coverPage/status.vue'
import dataFIll from '../views/dataElements/dataFIll.vue'
import applyFormCenter from '../views/formCenter/writeForm/applyForm/index.vue'
import rateFormCenter from '../views/formCenter/writeForm/rateForm/index.vue'
import '../views/formCenter/fixtures/global-components.js' // 需引入自定义组件

export default {
  name: 'app',
  components: { goal, status, dataFIll, applyFormCenter, rateFormCenter },
  data() {
    return {
      show: false,
      buCode: '',
      dcPeriod: '',
      formType: '',
      type: '',
      id: '',
      recordId: ''
    }
  },
  // tooltip等外部组件有bug无法正确渲染
  created() {
    const url = location.href
    const queryString = url.split('?')[1]
    const params = new URLSearchParams(queryString)
    this.buCode = params.get('buCode')
    this.dcPeriod = params.get('dcPeriod')
    this.type = params.get('type')?.split('#')[0]
    this.formType = params.get('formType')

    this.id = params.get('id')?.split('#')[0]
    // 表单中心
    this.recordId = params.get('recordId')?.split('#')[0] || ''
    this.intervalId = setInterval(() => {
      const token = localStorage.getItem('Authorization')
      if (token) {
        clearInterval(this.intervalId)
        this.show = true
      }
    }, 500)
  },
  beforeDestroy() {
    if (this.intervalId) {
      clearInterval(this.intervalId)
    }
  }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* text-align: center;
  color: #2c3e50; */
}
</style>
